﻿using Light.Utility;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Data;

namespace Light.Framework
{
    /// <summary>
    /// SQL日志记录类
    /// </summary>
    class SQLLoger
    {
        /// <summary>
        /// 记录程序执行的SQL语句
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="listParams"></param>
        public static void Write(string sql, params IDataParameter[] listParams)
        {
            if (ApplicationSetting.ReadAppSetting("sql.log", false))
            {
                string filename = "sql.log";

                TextHelper.Console(filename, "\r\n===" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "==\r\n");
                TextHelper.Console(filename, sql + "\r\n");

                foreach (var item in listParams)
                {
                    TextHelper.Console(filename, item.ParameterName + "=" + item.Value);
                }
            }
        }
    }
}
